package io.kimmking.gateway.ratelimiter;

import com.google.common.collect.Lists;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;

@NoArgsConstructor
@Data
public class RateLimiterConfigEntity {

    //SCG里的route ID
    @Getter
    private String route_id;

    //需要进行限速的接口url列表
    private List<String> rateLimitUrls = Lists.newLinkedList();

    //令牌生成速率
    @Getter
    private int replenishRate;

    //令牌桶的容量
    @Getter
    private int burstCapacity = 1;

    //需要消耗的令牌数量
    @Getter
    private int requestedTokens = 1;


    public List<String> getRateLimitUrls() {
        return rateLimitUrls;
    }

    //重写equals和hashCode方法
    @Override
    public boolean equals(Object o){
        if(this == o) return true;
        if(o==null || getClass() != o.getClass()) return false;
        RateLimiterConfigEntity rateLimiterConfigEntity = (RateLimiterConfigEntity)o;
        return Objects.equals(route_id,rateLimiterConfigEntity.route_id) &&
                Objects.equals(rateLimitUrls,rateLimiterConfigEntity.rateLimitUrls) &&
                Objects.equals(replenishRate,rateLimiterConfigEntity.replenishRate) &&
                Objects.equals(burstCapacity,rateLimiterConfigEntity.burstCapacity) &&
                Objects.equals(requestedTokens,rateLimiterConfigEntity.requestedTokens);
    }

    @Override
    public int hashCode(){
        return Objects.hash(route_id, rateLimitUrls, replenishRate,
                burstCapacity, requestedTokens);
    }

    @Override
    public String toString() {
        return "RateLimiterConfigEntity{" +
                "route_id=" + route_id + ", rateLimitUrls=" + rateLimitUrls +
                ", replenishRate=" + replenishRate + ", burstCapacity=" +
                burstCapacity + ", requestedTokens=" + requestedTokens + "}";
    }
}
